package com.lv.LvRefundRecord.service;
import com.aqgj.util.JsonWrapper;
import com.lv.LvRefundRecord.bean.LvRefundRecord;
import com.lv.LvRefundRecord.dao.LvRefundRecordDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service("LvRefundRecord")
public class LvRefundRecordManager {
    @Autowired
    LvRefundRecordDao lvRefundRecordDao;

    /**
     * 获取退款列表
     * @param pageNo  页码
     * @param pageSize 条数
     * @param cid   当前公司ID
     * @return  列表集合
     */
    public List getRecordList(int pageNo, int pageSize, String cid) {
        List list = lvRefundRecordDao.getRecordList(pageNo, pageSize, cid);
        if (list.size() == 0) {
            return null;
        }
        return lvRefundRecordDao.getKeyList(list, "id", "name", "type", "orderNumber", "orderBalance", "money", "addTime");
    }

    /**
     * 获取退款总数
     *
     * @return 退款总条数
     */
    public Integer getSqlSumQuery(String cid) {
        return lvRefundRecordDao.getSqlSumQuery(cid);
    }

    public LvRefundRecord get(String zid) {
        return lvRefundRecordDao.get(zid);
    }

    /**
     * 退款记录详情
     * @param rid  退款ID
     * @return MAP
     */
    public HashMap<String, Object> getRecordInfo(String rid) {
        Object[] objects=  lvRefundRecordDao.getRecordInfo(rid);
        String[] result={"name","refundType","orderNumber","orderBalance","payBalance","payType","orderTime","refundMoney","refundTime","serverDate","personnel"};
        HashMap<String,Object> map=new HashMap<>();
        if(objects!=null){
            for (int i=0;i<result.length;i++) {
                map.put(result[i],objects[i]);
            }
        }
        return JsonWrapper.successWrapper(map);
    }
}
